/**
 * 产品实体类 - 支付产品的定义和管理实体
 *
 * 开发人员：陈宏伟
 * 开发时间：2025-10-25 至 2025-10-30
 * 模块职责：定义支付产品的基本信息和业务属性，支持产品管理和支付订单关联
 *
 * 技术要点：
 * - 多租户关联设计，与企业实体关联
 * - 产品状态枚举管理，支持多种产品状态
 * - 金额精度控制，使用BigDecimal确保价格准确性
 * - 货币类型支持和国际化考虑
 * - 产品分类和排序管理功能
 *
 * 开发故事：负责产品实体的数据模型设计，与支付服务层深度配合，实现产品信息的完整管理和支付订单的产品关联。
 */
package com.pbl.entity;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.*;

import javax.persistence.*;
import java.math.BigDecimal;
import java.time.LocalDateTime;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Entity
@Table(name = "products")
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
public class Product {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "enterprise_id", nullable = false)
    private Enterprise enterprise;

    @Column(name = "code", nullable = false, length = 64)
    private String code;

    @Column(name = "name", nullable = false, length = 128)
    private String name;

    @Column(name = "description", columnDefinition = "TEXT")
    private String description;

    @Column(name = "category", nullable = false, length = 64)
    private String category;

    @Column(name = "price", nullable = false, precision = 12, scale = 2)
    private BigDecimal price;

    @Column(name = "currency", nullable = false, length = 8)
    @Builder.Default
    private String currency = "CNY";

    @Enumerated(EnumType.STRING)
    @Column(name = "status", nullable = false, length = 16)
    @Builder.Default
    private ProductStatus status = ProductStatus.ACTIVE;

    @Column(name = "sort_order", nullable = false)
    @Builder.Default
    private Integer sortOrder = 0;

    @Column(name = "created_at", insertable = false, updatable = false)
    private LocalDateTime createdAt;

    @Column(name = "updated_at", insertable = false, updatable = false)
    private LocalDateTime updatedAt;

    public enum ProductStatus {
        ACTIVE, INACTIVE, DISCONTINUED
    }
}
